<template>
	<div class="examine-data">
		<div class="platform-goods-examine">
			<div class="chart-menu">
				<div class="chart-menu-left">
					<div class="date-select">
						<el-select v-model="year" placeholder="年份" @change="chartdateSelect()">
							<el-option v-for="item in yearOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</div>
					<div class="type-select">
						<el-select v-model="type" placeholder="类型" @change="chartdateSelect()">
							<el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</div>
				</div>
			</div>
			<BarChart :chart-data="orderData1"></BarChart>
		</div>
	</div>
</template>

<script>
import BarChart from '@/components/BarChart';
export default {
	components: {
		BarChart
	},
	props: {
		layerid: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			orderData1: {
				tips: '审核商品总数',
				color: '#0F9AD5',
				date: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
				data: []
			},
			yearOptions: [
				{
					value: '2018',
					label: '2018'
				},
				{
					value: '2019',
					label: '2019'
				},
				{
					value: '2020',
					label: '2020'
				}
			],
			year: 2020,
			typeList: [
				{
					value: 0,
					label: '商品编辑审核'
				},
				{
					value: 1,
					label: '商品上传审核'
				}
			],
			type: 0
		};
	},
	methods: {
		init() {
			let data = {
				type: this.type,
				day: 2,
				time: this.year
			};
			this.$http(this.$ApiList.ExamineGoodsData, data).then(res => {
				this.orderData1.data = this.proofreadingTime(res.datas.add);
			});
		},
		proofreadingTime(data) {
			let orderData = [];
			let addTimeList = [];
			let dateContrast = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
			data.forEach(item => {
				addTimeList.push(item.add_time);
			});

			for (let i = 0; i < dateContrast.length; i++) {
				let index = addTimeList.indexOf(dateContrast[i]);
				if (index != -1) {
					orderData.push(data[index].counts);
				} else {
					orderData.push(0);
				}
			}
			return orderData;
		},
		chartdateSelect() {
			this.init();
		}
	},
	created() {
		this.init();
	}
};
</script>
<style lang="scss">
.examine-data {
	width: 100%;
	padding: 20px 20px;
	.platform-goods-examine {
		width: 100%;
	}
	.chart-menu-left{
		display: flex;
	}
}
</style>
